package com.wa.annotations.lifecycle;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Data
@AllArgsConstructor
public class LifeCycleAll implements InitializingBean, DisposableBean {

    /**
     *  初始化第一步
     */
    @PostConstruct
    public void postConstruct() {
        System.out.println("LifeCycleAll PostConstruct注解");
    }

    /**
     *  初始化第二步
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("LifeCycleAll InitializingBean.afterPropertiesSet方法");
    }

    /**
     *  初始化第三步
     */
    public void init() {
        System.out.println("LifeCycleAll init-method方法");
    }


    /**
     *  销毁第一步
     */
    @PreDestroy
    public void preDestroy() {
        System.out.println("LifeCycleAll preDestroy注解");
    }

    /**
     *  销毁第二步
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("LifeCycleAll DisposableBean.destroy方法");
    }

    /**
     *  销毁第三步
     */
    public void destroyMethod() {
        System.out.println("LifeCycleAll destroy-method方法");
    }
}


